home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-06-26 | 5.2 KB | 186 lines | [TEXT/MPS ] |
- /*
- File: AppleEventHandling.cp
-
- Contains: Minimalist support for the required and Display Manager AppleEvents
- We also support openning and printing “LetterSpec” documents for AOCE.
-
- To really support AppleScript™, we’ll do ALOT more work in here.
-
- Written by: Dave Falkenburg
-
- Copyright: © 1993-94 by Dave Falkenburg, all rights reserved.
-
- Change History (most recent first):
-
- */
-
- #include <Types.h>
- #include <AppleEvents.h>
- #include <Errors.h>
- #include <Displays.h> // for Display Manager AppleEvent constants
- #include <OCEStandardMail.h> // for LetterSpec
-
- #include "AppLib.h"
- #include "AppleEventHandling.h"
-
- void
- InstallAppleEventHandlers(void)
- {
- // It’s probably more efficient to use a table to install these handlers…
-
- (void) AEInstallEventHandler(kCoreEventClass,kAEOpenApplication,NewAEEventHandlerProc(HandleOpenApplication),0,false);
- (void) AEInstallEventHandler(kCoreEventClass,kAEOpenDocuments,NewAEEventHandlerProc(HandleOpenOrPrintDocuments),(long) &OpenDocument,false);
- (void) AEInstallEventHandler(kCoreEventClass,kAEPrintDocuments,NewAEEventHandlerProc(HandleOpenOrPrintDocuments),(long) &PrintDocument,false);
- (void) AEInstallEventHandler(kCoreEventClass,kAEQuitApplication,NewAEEventHandlerProc(HandleQuitApplication),0,false);
-
- if (gHasDisplayManager)
- (void) AEInstallEventHandler(kCoreEventClass,kAESystemConfigNotice,NewAEEventHandlerProc(HandleDisplayManagerNotice),0,false);
- }
-
-
- OSErr
- CheckAppleEventForMissingParams(AppleEvent *theAppleEvent)
- {
- DescType returnedType;
- Size actualSize;
- OSErr err;
-
- err = AEGetAttributePtr(theAppleEvent,keyMissedKeywordAttr,typeWildCard,
- &returnedType,nil,0,&actualSize);
-
- if (err == errAEDescNotFound) // If we couldn’t find the error attribute
- return noErr; // everything is ok, return noErr
-
- if (err == noErr) // We found an error attribute, so
- return errAEEventNotHandled; // tell the client we ignored the event
-
- return err; // Something else happened, return it
- }
-
-
- pascal OSErr
- HandleOpenApplication(AppleEvent *theAppleEvent,AppleEvent * /*reply*/,long /*refCon*/)
- {
- OSErr err;
-
- if ((err = CheckAppleEventForMissingParams(theAppleEvent)) != noErr)
- return err;
-
- return noErr;
-
- return(OpenNewDocument());
- }
-
-
- pascal OSErr
- HandleOpenOrPrintDocuments(AppleEvent *theAppleEvent,AppleEvent * /*reply*/,EachDocumentProcPtr docProc)
- {
- AEDescList documentList;
- long documentCount,documentIndex;
- AEKeyword keyword;
- DescType returnedType;
- Size actualSize;
- LetterDescriptor theLetterDesc;
- OSErr err;
-
- if ((err = AEGetParamDesc(theAppleEvent,keyDirectObject,typeAEList,&documentList)) != noErr)
- return err;
-
-
- // NOTE: If we are printing under GX we should get the printer info here
-
-
- if ((err = CheckAppleEventForMissingParams(theAppleEvent)) != noErr)
- return err;
-
- if ((err = AECountItems(&documentList,&documentCount)) != noErr)
- return err;
-
- for (documentIndex=1;documentIndex <= documentCount;documentIndex++)
- {
- // What kind of document is it?
- if ((err = AESizeOfNthItem(&documentList,documentIndex,&returnedType,&actualSize)) != noErr)
- return err;
-
- // Is it an AOCE letter?
- if (returnedType == typeLetterSpec)
- {
- // It’s a letter
- theLetterDesc.onDisk = false;
- err = AEGetNthPtr(&documentList,documentIndex,typeLetterSpec,&keyword,&returnedType,
- (Ptr) &theLetterDesc.u.mailboxSpec, sizeof(theLetterDesc.u.mailboxSpec),&actualSize);
- }
- else
- {
- // It’s just a normal document file
- theLetterDesc.onDisk = true;
- err = AEGetNthPtr(&documentList,documentIndex,typeFSS,&keyword,&returnedType,
- (Ptr) &theLetterDesc.u.fileSpec,sizeof(theLetterDesc.u.fileSpec),&actualSize);
- }
-
- if (err == noErr)
- (*docProc)(&theLetterDesc);
- }
-
- return noErr;
- }
-
-
- pascal OSErr
- HandleQuitApplication(AppleEvent *theAppleEvent,AppleEvent * /* reply */,long /* refCon */)
- {
- OSErr err;
-
- if ((err = CheckAppleEventForMissingParams(theAppleEvent)) != noErr)
- return err;
-
- gDone = QuitApplication();
-
- if (gDone)
- return noErr;
- else
- return userCanceledErr;
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //
- // Display Manager Suite is “Under Construction”
- //
- // To Do: Check ERS for Display Manager events
-
- pascal OSErr
- HandleDisplayManagerNotice(AppleEvent *theAppleEvent,AppleEvent * /* reply */,long /* refCon */)
- {
- AEDescList displayList;
- long displayCount,displayIndex;
- OSErr err;
-
- DebugStr((StringPtr) "\pGot Display Manager Event!");
-
- if ((err = AEGetParamDesc(theAppleEvent,kAEDisplayNotice,typeAEList,&displayList)) != noErr)
- return err;
-
- if ((err = CheckAppleEventForMissingParams(theAppleEvent)) != noErr)
- return err;
-
- if ((err = AECountItems(&displayList,&displayCount)) != noErr)
- return err;
-
- if ((err = CheckAppleEventForMissingParams(theAppleEvent)) != noErr)
- return err;
-
- for (displayIndex = 1; displayIndex<=displayCount; displayIndex++)
- {
- DebugStr((StringPtr) "\pProcessing a display");
-
- // Check to see if a display has gone offline, if so, move windows that were on
- // that display to a better place on the remaining displays
-
- // We probably want a utility method like TWindow::NudgeOnScreen() to share
- // with window positioning code as well.
- }
-
- return errAEEventNotHandled; // we really don’t handle this yet
- }
-